makeArrow <- function(from=c(x=0,y=0), to=c(x=1,y=1), width=0.1){
   #simple arrow no arrow head
   
   diff <- to - from
   traverse <- c(1, -diff[1]/diff[2])
   traverse <- traverse/sum(traverse^2)
   
   coords <- matrix(0, ncol=2, nrow=5)
   coords[1,] <- from + width*traverse
   coords[2,] <- to + width*traverse
   coords[3,] <- to - width*traverse
   coords[4,] <- from - width*traverse
   coords[5,] <- from + width*traverse
   Polygons(list(Polygon(coords, hole=FALSE)), "test")
}

#' make arrows
makeArrows <- function(fromto, locations, scale=0.1){
   len <- nrow(fromto)
   
   ids <- row.names(locations)
   from <- match(fromto$from, ids)
   from <- cbind( x = locations$x[from]
                , y = locations$y[from]
                )
   
   to <- match(fromto$to, ids)
   to <- cbind( x = locations$x[to]
              , y = locations$y[to]
              )
   
   width <-scale * fromto$value / max(fromto$value, na.rm=TRUE)
   
   #simple arrow no arrow head
   diff <- to - from
   traverse <- cbind(x=diff[,2], y=-diff[,1])/diff[,2]
   traverse <- traverse/sqrt(rowSums(traverse^2))
   coords <- array(0, dim=c(5,len, 2))
   coords[1,,] <- from + width*traverse
   coords[2,,] <- to + width*traverse
   coords[3,,] <- to - width*traverse
   coords[4,,] <- from - width*traverse
   coords[5,,] <- from + width*traverse
   
   arrowids <- paste(fromto$from,"->",fromto$to)
   pol <- lapply(1:len, function(i){
      Polygons(list(Polygon(coords[,i,], hole=FALSE)), arrowids[i])
   })
   pol
}